<?php
/**
 * 报表XML加载
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Xml.php 1059 2011-11-18 09:26:15Z mmxie $
 */
class IG_Data_Adapter_Xml extends IG_Data_Adapter_Abstract
{
    private $_path;

    public function __construct($config = array())
    {
        if (isset($config['path'])) $this->setPath($config['path']);
    }

    /**
     * 加载配置
     * @param int $id
     */
    public function loadConfig($id)
    {
        $file = $this->getPath() . $id . ".xml";
        if (!file_exists($file)) {
            throw new IG_Exception("文件'$file'不存在");
        }

        $config = new Zend_Config_Xml($file);
        $config = $config->toArray();
        if (isset($config['plugins']['plugin'])) {
            $config['plugins'] = $config['plugins']['plugin'];
        }
        $this->setConfig($config);
        return $this;
    }

    /**
     * 设置XML保存路径
     * @param $path
     * @return IG_Data_Adapter_Xml
     */
    public function setPath($path)
    {
        $this->_path = $path;
        return $this;
    }

    /**
     * 存放 XML 的文件夹
     * @return string
     */
    public function getPath()
    {
        if (!isset($this->_path)) {
            $this->_path = APPLICATION_PATH . "/../data/report/";
        }
        return $this->_path;
    }
}